﻿@using Seal.Model
@{
    ReportView view = Model;
    Report report = view.Report;
    ReportModel reportModel = view.Model;
    ReportView datatableView = report.FindViewFromTemplate(view.Views, ReportViewTemplate.DataTableName);


    if (datatableView != null && datatableView.GetBoolValue("invert_data_tables") && !view.IsServerPaginationEnabled)
    {
        reportModel.InvertDataTables();
    }
    string separator = view.GetValue("csv_separator");
    separator = string.IsNullOrEmpty(separator) ? report.Repository.Configuration.CsvSeparator : separator;
    separator = string.IsNullOrEmpty(separator) ? report.Repository.CultureInfo.TextInfo.ListSeparator : separator;
    bool useFormat = view.GetBoolValue("use_display_format");
}
@foreach (ResultPage page in reportModel.Pages)
{
    if (page.PageTable != null && view.GetBoolValue("show_page_tables") && page.PageTable.RowCount == 2 && page.PageTable.ColumnCount > 0)
    {
        for (int i = 0; i < page.PageTable.ColumnCount; i++)
        {
            ResultCell header = page.PageTable[0,i];
            ResultCell value = page.PageTable[1,i];
            @Raw(header.CSVValue(false, separator) + value.CSVValue(useFormat, separator) + "\r\n")
        }
    }
    if (page.DataTable != null && view.GetBoolValue("show_data_tables"))
    {
        for (int row = 0; row < page.DataTable.RowCount; row++)
        {
            for (int col = 0; col < page.DataTable.ColumnCount; col++)
            {
                if ((datatableView != null && datatableView.IsColumnHidden(col)) || page.DataTable.IsColumnHidden(col)) { continue; }
                @Raw(page.DataTable[row,col].CSVValue(useFormat, separator))
            }
            @Raw("\r\n")
        }
    }
}

